package com.liangzhong.modules.Main.Mediator
{
	import com.common.queueloader.QueueLoader;
	import com.common.queueloader.QueueLoaderEvent;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.constants.ApplicationConstants;
	import com.liangzhong.constants.NotificationConstants;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.BagEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.mediator.BaseMediator;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.liangzhong.model.type.GoodsType;
	import com.liangzhong.model.type.OtherGoodType;
	import com.liangzhong.proxy.user.UserProxy;
	
	import common.IGetPropView;
	
	import flash.display.DisplayObject;
	
	import lz.controls.Alert;
	import lz.controls.managers.PopUpManager;
	
	import org.puremvc.as3.interfaces.INotification;

	/**
	 *逻辑控制 
	 * @author lxh
	 * 
	 */	
	public class LogicMediator extends BaseMediator
	{
		public static const MediatorName :String = "LogicMediator";
		/**
		 *是否俱乐部升级 
		 */		
		protected var isClubUpgrade :Boolean = false;
		/**
		 *加载器 
		 */		
		private var loader :QueueLoader;
		/**
		 *加载器1 
		 */		
		private var loader1 :QueueLoader;
		
		public function LogicMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
		}
		/**
		 * 
		 * 添加事件
		 */		
		override public function addEventListeners():void
		{
			AppEventDispatcher.getInstance().addEventListener(BagEvent.USE_ITEM,useItemHandler);
		}
		/**
		 * 
		 * 删除事件
		 */		
		override public function removeEventListeners():void
		{
			
		}
		/**
		 *使用物品 
		 * @param e
		 * 
		 */		
		private function useItemHandler(e :BagEvent):void
		{
			var goodsVo :GoodsVo = e.param;
			switch(goodsVo.type)
			{
				//无法直接使用
				case GoodsType.FOOTWEAR:
				case GoodsType.ATTRIBUTE:
				case GoodsType.MATERIAL:
				{
					Alert.showErrorTip("该物品无法直接使用");
					return;
				}
					//部分无法直接使用
				case GoodsType.OTHER:
				{
					switch(goodsVo.ntype)
					{
						case OtherGoodType.CALLINCARD:
						case OtherGoodType.FRESHCARD:
						case OtherGoodType.FUCKLYCARD:
						case OtherGoodType.MEDICALCARD:
						case OtherGoodType.PHYSICAL:
						case OtherGoodType.PROTECTCARD:
						case OtherGoodType.MORALE:
						case OtherGoodType.CUIHUAJI:
						{
							Alert.showErrorTip("该物品无法直接使用");
							return;
						}
					}
					break;
				}
			}
			this.sendNotification(ApplicationConstants.BAG_USE_ITEM,e.param);
		}
		/**
		 *酒吧获取奖励
		 * @param e
		 * 
		 */		
		private function wineGetAwardHandler(e :ModuleEvent):void
		{
			this.sendNotification(ApplicationConstants.WINEBAR_GETAWARD,e.param);
		}
		/**
		 * 捕获通知
		 * @param notification
		 * 
		 */		
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName())
			{
			}
		}
		/**
		 *显示获取物品面板 
		 * @param pids
		 * 
		 */		
		private function showGetPropView(pids :Array):void
		{
			var getPropView :IGetPropView = Reflection.createInstance("common.propAward.view.GetPropView");
			getPropView.initUI();
			getPropView.data = pids;
			PopUpManager.addWindow(getPropView as DisplayObject,GlobalDef.GameWindowContainer,0,0,true);
		}
		/**
		 * 注册感兴趣的命令
		 * @return 
		 * 
		 */		
		override public function listNotificationInterests():Array
		{
			return [NotificationConstants.MATCH_START_LOAD_RES,
				NotificationConstants.COMMON_GET_PROP];
		}
		/**
		 * 
		 * 注册进行时
		 */		
		override public function onRegister():void
		{
			//setTimeout(clubLineUpEffect,1000);//test club line up
			addEventListeners();
			var userProxy :UserProxy = new UserProxy();
			facade.registerProxy(userProxy);
			//预加载资源
			loader = new QueueLoader();
			loader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE,onLoadItemComplete);
			loader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE,onLoadQueueComplete);
			//加载器1
			loader1 = new QueueLoader();
			loader1.addEventListener(QueueLoaderEvent.ITEM_COMPLETE,onLoadItemComplete);
			loader1.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE,onLoadQueueComplete1);
			
			var releaseVersion :String = "?" + GlobalDef.ReleaseVersion;
			//zip
			//var tempTime :Number = getTimer();
			//AppData.getInstance().goodsManager.parseGoodsList();
			//AppData.getInstance().bufferManager.parseBufferList();
			//AppData.getInstance().npcClubManager.parseList();
			//AppEventDispatcher.getInstance().dispatchEvt(NotifierEvent.RES_CONFIG_LOAD_COMPLETE);
			//trace("use time:",getTimer() - tempTime);
			//loader.addQueue(new QueueVo("Config_zip"),"res/config/config.zip" + releaseVersion + ".zip");
			//泡吧奖励资源
			//loader.addQueue(new QueueVo("winebaraward"),"res/swf/winebar/WineBarReward.swf" + releaseVersion + ".swf");
			//任务
			//loader.addQueue(new QueueVo("task"),"res/swf/task/task.swf" + releaseVersion + ".swf");
			//队徽
			//loader1.addQueue(new QueueVo("teamIcon"),"res/swf/common/teamIcon.swf" + releaseVersion + ".swf");
			//loader.queueLoadStart();
			//loader1.queueLoadStart();
		}
		/**
		 * item complete
		 * @param e
		 * 
		 */		
		private function onLoadItemComplete(e:QueueLoaderEvent):void
		{
			if(e.queueVo == null)
			{
				return;
			}
			///解析
			var resConfig :XML;
			switch(e.queueVo.queueName)
			{
				case "winebaraward"://泡吧奖励资源
				{
					
					break;
				}
			}
		}
		/**
		 * queue complete
		 * @param e
		 * 
		 */		
		private function onLoadQueueComplete(e :QueueLoaderEvent):void
		{
			loader.removeEventListener(QueueLoaderEvent.ITEM_COMPLETE,onLoadItemComplete);
			loader.removeEventListener(QueueLoaderEvent.QUEUE_COMPLETE,onLoadQueueComplete);
			loader = null;
			//test
			//var mawVo :MatchEndAwardVo = new MatchEndAwardVo();
			//mawVo.pids = [{id:1,type:4},{id:8,type:4},{id:3,type:4},{id:4,type:4}];
			//TweenLite.delayedCall(1,matchAward,[mawVo]);
		}
		/**
		 * queue complete
		 * @param e
		 */		
		private function onLoadQueueComplete1(e :QueueLoaderEvent):void
		{
			loader1.removeEventListener(QueueLoaderEvent.ITEM_COMPLETE,onLoadItemComplete);
			loader1.removeEventListener(QueueLoaderEvent.QUEUE_COMPLETE,onLoadQueueComplete);
			loader1 = null;
		}
	}
}